package gameFile;

import java.awt.Color;
import java.awt.Graphics;

import gameFile.GamePlay.*;

public class WallSegment implements Comparable<WallSegment>{
	  
	  private int playerID;
	  private Color wallColor;
	  private int xStart;
	  private int yStart;
	  public Axis axis;
	  private int length;
	  public boolean fixed;

	  public WallSegment() {
		this.playerID = 0;
		this.xStart = 0;
		this.yStart = 0;
		this.axis = Axis.UPDOWN;
		this.length = 0;
		this.fixed = false;
		this.wallColor = Color.green;
	  }
	  
	  public WallSegment(int playerID, int x, int y, Direction dir) {
		this.playerID = playerID;
		this.xStart = x;
		this.yStart = y;
		this.axis = getAxis(dir);
		this.length = 0;
		this.fixed = false;
		this.wallColor = Color.green;
	  }

	public WallSegment(int playerID, int x, int y, int length, Direction dir,Color color) {
		this.playerID = playerID;
		this.xStart = x;
		this.yStart = y;
		this.axis = getAxis(dir);
		this.length = length;
		this.fixed = false;
		this.wallColor = color;
	}

	public WallSegment(LightBike player)
	{	this.playerID = player.getID();
		this.xStart = player.getXPosition();
		this.yStart = player.getYPosition();
		this.axis = getAxis(player.getDirection());
		this.length = 0;
		this.fixed = false;
		this.wallColor = player.getWallColor();
	}
	  public int getXstart() {
		  return xStart;
	  }

	  public int getYstart() {
		  return yStart;
	  }

	  public int getXend() {
		  if(axis == Axis.LEFTRIGHT)
			  return (xStart + length);
		  else
			  return xStart;
	  }

	  public int getYend() {
		  if(axis == Axis.UPDOWN)
			  return (yStart + length);
		  else
			  return yStart;
	  }

	  public void appendLength(int addedLength) {
		  length += addedLength;
	  }

	  public void setLength(int len) {
		  length = len;
	  }
	  
	  public int getLength() {
		  return length;
	  }
	  
	  public int getID(){
		  return playerID;
	  }
	  
	  public Axis getAxis(Direction dir){
			
			if(dir == Direction.UP || dir == Direction.DOWN)
				return Axis.UPDOWN; 
			else
				return Axis.LEFTRIGHT;
	  }
	  
	  public void drawWall(Graphics g) {
	    	g.setColor(wallColor);
			g.drawLine(getXstart(), getYstart(), getXend(), getYend());
	  }

	@Override
	public int compareTo(WallSegment wall) {
		
		
		
		if(this.fixed != wall.fixed){
			if(this.fixed) return 1;
			else return -1;
		}
		else
		{
			if(this.xStart < wall.getXstart())
				return -1;
			else if(this.xStart > wall.getXstart())
				return 1;
			else
			{
				if(this.yStart < wall.getYstart())
					return -1;
				else if(this.yStart > wall.getYstart())
					return 1;
				else
				{
					if(this.playerID < wall.playerID)
						return -1;
					else if(this.playerID > wall.playerID)
						return 1;
					else
					{
						if(this.length < wall.length)
							return -1;
						else if(this.length > wall.length)
							return 1;
						else
						{
							if(this.axis != wall.axis)
							{
								if(this.axis == Axis.LEFTRIGHT)
									return -1;
								else
									return 1;
							}
							else
								return 0;
						}
					}
				}
			}
		}
	}
}
